//
//  LaunchGifViewone.m
//  safeLady
//
//  Created by xmy on 2016/12/14.
//  Copyright © 2016年 xmy. All rights reserved.
//

#import "LaunchGifViewone.h"
@interface LaunchGifViewone()
@property (weak, nonatomic) IBOutlet UIImageView *backgroundImg;
@property (weak, nonatomic) IBOutlet UIImageView *personImg;
@property (weak, nonatomic) IBOutlet UIImageView *imgJing;

@end

@implementation LaunchGifViewone

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(void)awakeFromNib{
    [super awakeFromNib];
    [self setBackGroundImgAnimation];
    [self setPersonGroundAnimation];
}
-(void)setBackGroundImgAnimation{
    CABasicAnimation *scaleAnima = [CABasicAnimation animationWithKeyPath:@"transform.scale"];//同上
    scaleAnima.toValue = [NSNumber numberWithFloat:2.0f];
    scaleAnima.duration = 5.0f;
    scaleAnima.timingFunction = [CAMediaTimingFunction functionWithName:
                                 kCAMediaTimingFunctionLinear];
    scaleAnima.fillMode =kCAFillModeForwards;
    scaleAnima.removedOnCompletion = NO;
    [self.backgroundImg.layer addAnimation:scaleAnima forKey:@"scaleAnimation"];
}
-(void)setPersonGroundAnimation{
    CAKeyframeAnimation *positionAnima = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(ScreenWidth/2, ScreenHeight-self.personImg.height/2,0,10)];
    positionAnima.path = path.CGPath;
    positionAnima.duration = 1.0f;
    positionAnima.repeatCount=5.0f;
    CABasicAnimation *momAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
    momAnimation.fromValue = [NSNumber numberWithFloat:-7];
    momAnimation.toValue = [NSNumber numberWithFloat:7];
    momAnimation.beginTime = 5.3f;
    momAnimation.duration = 0.2;
    momAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    CAAnimationGroup *groupAnimation = [CAAnimationGroup animation];
    groupAnimation.animations = [NSArray arrayWithObjects:positionAnima,momAnimation, nil];
    groupAnimation.duration = 5.5f;
    [self.personImg.layer addAnimation:groupAnimation forKey:@"groupAnimation"];
    [UIView animateWithDuration:0.3 delay:5.4 options:UIViewAnimationOptionCurveLinear animations:^(void){
        self.imgJing.alpha = 1.0 ;
    } completion:^(BOOL finish){
    }];


}
@end
